package com.rain.service.product;
import java.time.LocalDateTime;

import com.rain.feign.orders.api.OrderFeign;
import com.rain.persistence.product.domain.ProductDO;
import com.rain.persistence.product.manager.ProductManager;
import com.rain.persistence.product.manager.impl.ProductManagerImpl;
import io.seata.spring.annotation.GlobalTransactional;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author: wu
 * @date: 2021/4/4
 */
@Service
@Slf4j
public class ProductService {

    @Autowired
    private ProductManager productManager;
    @Autowired
    private OrderFeign orderFeign;

    @GlobalTransactional(rollbackFor = Exception.class)
    @Transactional(rollbackFor = Exception.class)
    public Boolean deductNum() {
        Boolean result = orderFeign.saveOrder();
        log.error("订单新增结果:{}",result);
        throw new RuntimeException("库存减少失败");
//        ProductDO productDO = new ProductDO();
//        productDO.setPrice(10.0D);
//        productDO.setStock(1);
//        productDO.setLastUpdateTime(LocalDateTime.now());
//        productManager.save(productDO);
//        return Boolean.TRUE;
    }
}
